use rand::Rng;

pub fn main() {
    let have_list = false;
    if have_list
    {
        luck_have_list();
    }
    else
    {
        luck_not_list();
    }
}

fn luck_not_list()
{
    let guess_amount = 1_000_000;
    let mut count = 0;
    let mut luck_count_change = 0;
    let mut luck_count_dont = 0;
    let mut rng = rand::thread_rng();

    while guess_amount > count
    {
        count += 1;
        let element: u8 = rng.gen_range(0..3);
        if do_change(element)
        {
            luck_count_change += 1;
        }
        if dont_change(element)
        {
            luck_count_dont += 1;
        }
    }

    println!("guess count is: {}, change luck count: {}, not change luck count: {}",
             count, luck_count_change, luck_count_dont);
}

fn luck_have_list()
{
    let mut guess_list: [u8; 1000_000] = [0; 1000_000];
    let mut luck_count_change = 0;
    let mut luck_count_dont = 0;
    create_list(&mut guess_list);

    for element in guess_list.iter()
    {
        if do_change(*element)
        {
            luck_count_change += 1;
        }
        if dont_change(*element)
        {
            luck_count_dont += 1;
        }
    }

    println!("guess list len is: {}, change luck count: {}, don't change luck count: {}",
             guess_list.len(), luck_count_change, luck_count_dont);
}

fn create_list(guess_list: &mut [u8])
{
    let length = guess_list.len();
    let mut rng = rand::thread_rng();
    for i in (0..length).rev()
    {
         let door_have = rng.gen_range(0..3);
         guess_list[i] = door_have;
    }
}

fn do_change(element: u8) -> bool
{
    let choose = 
        if element != 2
        {
            1
        }
        else
        {
            2
        };

    do_luck(choose, element)
}

fn dont_change(element: u8) -> bool
{
    let choose = 0;
    do_luck(choose, element)
}

fn do_luck(choose: u8, element: u8) -> bool
{
    if choose == element
    {
        true
    }
    else
    {
        false
    }
}
